home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / patchSG0002222.idb / var / www / cgi-bin / wrap.z / wrap
Encoding:
Text File  |  1997-07-30  |  20.4 KB  |  889 lines

  1. #!/usr/bin/perl
  2.  
  3. #__________________________________________________________
  4. #
  5. #    File:    wrap
  6. #    By:      Matt Ho
  7. #   Date:    7/23/95
  8. #   Purpose: Wrapper to dynamically create HTML documents
  9. #            that contain a easy to read directory content.
  10. #__________________________________________________________
  11.  
  12.  
  13. require "flush.pl";
  14.  
  15. #__________________________________________________________
  16. #
  17. #   SGI Patch 2222 disables the 'download' feature for
  18. #   security reasons. This functionality will removed
  19. #   entirely in the next release.
  20. #
  21. #   The supported way for a user to download a file is
  22. #   to use the browser 'Save Link' feature.
  23. #
  24. #   If you need to restore this functionality, and you are
  25. #   behind a firewall, and trust all others behind that
  26. #   firewall, then change the line below to:
  27. #        $HANDLER_DISABLED = 0 ;
  28. #__________________________________________________________
  29.  
  30. $HANDLER_DISABLED = 1 ;
  31.  
  32. #__________________________________________________________
  33. #
  34. #    Set some environment variables, we'll need through the
  35. #    script and do some initial error checking.
  36. #__________________________________________________________
  37.  
  38. $ROOT     = "/var/www/htdocs" ;    # Root directory
  39. $PATH     = $ENV{'PATH_INFO'} ; 
  40. $wrap     = "/cgi-bin/wrap" ;        # Script alias for this CGI
  41. $ls       = "/sbin/ls -a1" ;
  42. $outboxcgi = "/var/www/cgi-bin/outbox-cgi" ;
  43. #__________________________________________________________
  44. #
  45. #    Read the form data in.  PATH_INFO may be passed here
  46. #    if this was called from a SSI.  We're going to make
  47. #    one final tweak and read from the arg list as well
  48. #    for SSI's.
  49. #__________________________________________________________
  50.  
  51. if( $ENV{'REQUEST_METHOD'} eq "GET" )
  52. {
  53.    $buffer=$ENV{'QUERY_STRING'} ;
  54. else
  55. {
  56.    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}) ;
  57. }
  58.  
  59. @pairs = split(/&/, $buffer) ;
  60. foreach (@pairs)
  61. {
  62.     tr/+/ / ;    
  63.    ($name,$value) =  split(/=/) ;
  64.     $value        =~ s/%(..)/pack("c",hex($1))/ge ;
  65.     $name         =~ s/%(..)/pack("c",hex($1))/ge ;
  66.  
  67.     $FORM{$name} = $value ;
  68. }
  69.  
  70. #_________________________________
  71. #
  72. #    Some basic checks to take
  73. #    care of
  74. #_________________________________
  75.  
  76. if( $ARGV[0] )
  77. {
  78.     $PATH = $ARGV[0] ;
  79.     $arg  = 1 ;
  80. }
  81.  
  82. # trim off undesirable meta chars.
  83. $PATH =~ s/[|;]//g ;
  84.  
  85. chop $PATH if substr($PATH, -1) eq "/" ;
  86. @_        = split('/', $PATH) ;
  87. $pathRoot = $_[$#_] ;
  88. $doc      = $ROOT.$PATH ;
  89.  
  90. &ErrBadPath if ! defined $PATH || $PATH eq "" ; # check for empty path
  91. &ErrBadPath unless &ValidPath ;    # Check for server spoofing
  92. &ErrBadPath unless -e $doc ;    # Check to see it exists
  93. &ErrBadPath if -f $doc ;    # Don't allow download of file via wrap
  94.  
  95. #__________________________________________________________
  96. #
  97. #    If we get to this point, we can be reasonably certain
  98. #    that this is a valid shared directory.  We want to
  99. #    show it using the appropriate method.  The following
  100. #    section is the leading data.  ShowContents will supply
  101. #    the rest of the data.
  102. #
  103. #    We do, however, need to account for the user putting
  104. #    an index.html file in the directory.  We'll handle 
  105. #    that as follows.  If the file exists, it is assumed to
  106. #    be in the right.  We will append out data at the end,
  107. #    using the index.html's head section. Otherwise, we
  108. #    will use ours.
  109. #__________________________________________________________
  110.  
  111. if( $arg == 1 )
  112. {
  113.     #    This is intentionally left blank
  114. }
  115. elsif( -r "$doc/index.html" )
  116. {
  117.     print "Content-type: text/html\n\n" ;
  118.  
  119.     open(INDEX, "$doc/index.html") ;
  120.     while( <INDEX> )
  121.     {
  122.         s/<!--#exec/<!-- exec/g ;
  123.         last if /<\/[bB][oO][dD][yY]>/ ;
  124.         last if /<\/[hH][tT][mM][lL]>/ ;
  125.         print ;
  126.         if ( /<BODY/ || /<body/)
  127.         {
  128.             if ( ! />/ )
  129.             {
  130.             while( <INDEX> )
  131.             {
  132.                 print ;
  133.                 last if ( />/ ) ;
  134.             }
  135.             }
  136.             &flush(STDOUT) ;
  137.             system '/var/www/cgi-bin/outbox-cgi', $PATH;
  138.         }
  139.     }
  140.     close(INDEX) ;
  141. }
  142. else
  143. {
  144.     print <<ENDOFTEXT ;
  145. Content-type: text/html
  146.  
  147. <head>
  148.     <title>
  149.         $pathRoot
  150.     </title>
  151. </head>
  152.  
  153. <body bgcolor="c1c1c1" text="000000" link="0000ee" vlink="0000ee"
  154. alink="0000ff" background="/outbox/images/background.gif">
  155. ENDOFTEXT
  156.  
  157.         &flush(STDOUT) ;
  158.     system '/var/www/cgi-bin/outbox-cgi', $PATH ;
  159.     &flush(STDOUT) ;
  160.     print <<ENDOFTEXT ;
  161. <B>$pathRoot:</B>
  162. ENDOFTEXT
  163. }
  164.  
  165. #
  166. # RFE - people getting confused with all these choices.
  167. #
  168. #  &ShowSelection ;
  169.  
  170. &ShowContents ;
  171.  
  172. print "\n</body>\n</html>\n\n" unless $arg == 1 ;
  173.  
  174.  
  175.  
  176. #__________________________________________________________
  177. #__________________________________________________________
  178. #__________________________________________________________
  179.  
  180.  
  181.  
  182. sub ErrBadPath
  183. {
  184.     print <<ENDOFTEXT ;
  185. Content-type: text/html
  186.  
  187. <HTML>
  188. <HEAD><TITLE>OutBox: File Not Found</TITLE></HEAD>
  189. <BODY><H2>OutBox: File Not Found</H2>
  190. The requested file "$PATH" was not found on this OutBox page.
  191. <P>
  192. ENDOFTEXT
  193.  
  194. if( defined $ENV{'HTTP_REFERER'} )
  195. {
  196.     $referer = $ENV{'HTTP_REFERER'} ;
  197.     print <<ENDOFTEXT ;
  198. <a href="$referer"><IMG SRC="/outbox/images/go-back.gif" BORDER=0 ALT="Back"></A>
  199. ENDOFTEXT
  200. }
  201.  
  202.         print <<ENDOFTEXT ;
  203. </BODY>
  204. </HTML>
  205. ENDOFTEXT
  206.  
  207.  
  208.     exit ;
  209. }
  210.  
  211. #__________________________________________________________
  212.  
  213. sub ValidPath
  214. {
  215.     return 1 unless /\.\./ ;
  216.     
  217.     return '' if /^\.\./ ;
  218.     return '' if /\/\.\.\// ;
  219.     return '' if /\.\.$/ ;
  220.  
  221.     return 1 ;
  222. }
  223.  
  224. #__________________________________________________________
  225.  
  226. sub IsHiddenFile
  227. {
  228.         local($fname) = $_[$#_];
  229.  
  230.     return 1 if $fname eq "index\.html" ;
  231.     return 1 if $fname eq "index\.html\.O" ;
  232.     return 1 if $fname eq "index\.html\.N" ;
  233.     return 1 if $fname eq "index\.shtml" ;
  234.     return 1 if $fname eq "index\.shtml\.O" ;
  235.     return 1 if $fname eq "index\.shtml\.N" ;
  236.     return 1 if $fname eq "default\.gif" ;
  237.     return 1 if ( $fname =~ /^\./ ) ;
  238.     return 1 if ( $fname =~ /\.bak$/ ) ;
  239.     return 1 if ( $fname =~ /\.sav$/ ) ;
  240.     return 1 if ( $fname =~ /~$/ ) ;
  241.  
  242.     return '' ;
  243. }
  244.  
  245. #__________________________________________________________
  246.  
  247. sub ShowSelection
  248. {
  249.     local(@select) ;
  250.     
  251.     $FORM{'format'} = "default" unless defined $FORM{'format'} ;
  252.     $select{$FORM{'format'}} = "checked" ;
  253.  
  254.     print <<ENDOFTEXT ;
  255.  
  256. <center>
  257. <table cellpadding=2 cellspacing=0 border=0>
  258. <form action="$wrap$PATH" method=get>
  259. <tr>
  260.     <td><b>Viewing format:</b>
  261.         <input    type="radio"
  262.                 name="format"
  263.                 value="default"
  264.                 $select{'default'}> Default
  265.         <input    type="radio"
  266.                 name="format"
  267.                 value="long"
  268.                 $select{'long'}> Long
  269.         <input    type="radio"
  270.                 name="format"
  271.                 value="short"
  272.                 $select{'short'}> Short </th>
  273.     <td align=center>
  274.         <input type="submit" value="Apply"></td>    
  275. </tr>
  276. </form>
  277. </table>
  278. </center>
  279.  
  280. ENDOFTEXT
  281. }
  282.  
  283.  
  284. #__________________________________________________________
  285.  
  286. sub ShowContents
  287. {
  288.     local($format) = $FORM{'format'} ;
  289.  
  290.     #_________________________________
  291.     #
  292.     #    Get the directory and do
  293.     #    some sorting (directories)
  294.     #    come first, then files.
  295.     #_________________________________
  296.  
  297.     open (FIND,"$ls $ROOT$PATH |") ;
  298.     while( <FIND> )
  299.     {
  300.         chop ;
  301.         next if $_ eq "\." ;
  302.         next if ( $_ eq "\.\." && "/$pathRoot" eq  $PATH ) ;
  303.         next if ( /^\./ && $_ ne "\.\." ) ;
  304.         next if $_ eq "RCS" ;
  305.         next if ( ! -r "$ROOT$PATH/$_" ) ;
  306.         next if ( -d "$ROOT$PATH/$_" && ! -x "$ROOT$PATH/$_" ) ;
  307.         push(@d, $_), next if -d "$ROOT$PATH/$_" ;
  308.         push(@f, $_) ;
  309.     }
  310.  
  311.     #_________________________________
  312.     #
  313.     #    Select method of display
  314.     #_________________________________
  315.  
  316.     &ListFolders(@d) ;
  317.  
  318.     $format = "default" if ! defined $format ;
  319.  
  320.     if( $format eq "long" )
  321.     {
  322.         &ListLong(@f) ;
  323.     }
  324.     elsif( $format eq "short" )
  325.     {
  326.         &ListShort(@f) ;
  327.     }
  328.     else        # default format
  329.     {
  330.         &ListDefault(@f) ;
  331.     }
  332. }
  333.  
  334. #__________________________________________________________
  335.  
  336. sub ListFolders
  337. {
  338.     local($size) = $#_ + 1 ;
  339.     local($i) ;
  340.     local($j) ;
  341.     local($index) ;
  342.     local($format) ;
  343.     local($cols) = 3 ;
  344.     local($rows) = $size / $cols ;
  345.     local($left) = $size % $cols ;
  346.     local($label) ;
  347.     local($image) ;
  348.  
  349.     return if $size == 0 ;
  350.  
  351.     #_________________________________
  352.  
  353.     $format = "?format=$FORM{'format'}" if defined $FORM{'format'} ;
  354.  
  355.     #_________________________________
  356.  
  357.     $rows = sprintf("%.0d", $rows) ;
  358.     $rows++ if $left > 0 ;
  359.     
  360.     print <<ENDOFTEXT ;
  361. </center>
  362. <table cellpadding=0 cellspacing=0 width="100%" border=0>
  363. ENDOFTEXT
  364.     LOOP:
  365.     for( $i = 0 ; $i < $rows ; $i++ )
  366.     {
  367.         print "<tr>\n" ;
  368.         for( $j = 0 ; $j < $cols ; $j++ )
  369.         {
  370.             $index = $i + $j * $rows ;
  371.  
  372.             if( $index >= $size )
  373.             {
  374.                 print "<td></td>\n" ;
  375.                 next ;
  376.             }
  377.             if ( $_[$index] eq ".." )
  378.             {
  379.                 $label = "" ;
  380.                 $image = "/outbox/images/go-back.gif" ;
  381.             }
  382.             else
  383.             {
  384.                 $label = "$_[$index]" ;
  385.                 $image = "/outbox/images/file_folder.gif" ;
  386.             }
  387.  
  388.             print <<ENDOFTEXT ;
  389. <td>
  390.     <a href="$wrap$PATH/$_[$index]/$format"><img src="$image" align=middle border=0></a>
  391. ENDOFTEXT
  392.                         if ( $label ne "" )
  393.             {
  394.                 print "  <a href=\"$wrap$PATH/$_[$index]/$format\">$label</a>" ;
  395.                 }
  396.             print "</td>"
  397.         }
  398.         print "</tr>\n" ;
  399.     }
  400.  
  401.     print <<ENDOFTEXT ;
  402. </table>
  403. ENDOFTEXT
  404. }
  405.  
  406. #__________________________________________________________
  407.  
  408. sub ListDefault
  409. {
  410.     local(@notes) ;
  411.     local($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,@other) ;
  412.     local($USERPATH) = $PATH ;
  413.     local($first) = 1 ;
  414.     local($image) ;
  415.     local($url) ;
  416.  
  417.     $dltext = `/usr/bin/gettxt uxoutbox:22 "(download)"` ;
  418.  
  419.     return if ( $#_ == -1 ) ;
  420.  
  421.     substr($USERPATH, 0, 1) = "/~" ;
  422.  
  423.     print <<ENDOFTEXT ;
  424.  
  425. </center>
  426. <div align=left>
  427. ENDOFTEXT
  428.  
  429.     foreach (@_)
  430.     {
  431.             next if &IsHiddenFile($_) ;
  432.  
  433.         if ( /\.notes$/ )
  434.         {
  435.             $base = $_ ;
  436.             $base =~ s/\.notes$// ;
  437.             next if -r "$doc/$base" ;
  438.         }
  439.  
  440.         if ($first == 1)
  441.         {
  442.             $first = 0 ;
  443.             print "<HR ALIGN=LEFT WIDTH=\"80%\">\n" if ($#d >= 0) ;
  444.             print "<table cellpadding=0 cellspacing=1 border=0>" ;
  445.         }
  446.  
  447.         #_________________________________
  448.         #
  449.         #    Calculate the size of this
  450.         #    file
  451.         #_________________________________
  452.  
  453.         ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,@other) =
  454.             stat("$doc/$_") ; 
  455.  
  456.         if( $size == 1 )
  457.         {
  458.             $size = "<b>$size</b> byte" ;
  459.         }
  460.         elsif( $size >= 1024 )
  461.         {
  462.             $size = $size / 1024 ;
  463.             $size = sprintf("%.0d", $size) ;
  464.             $size = "<b>$size</b> KB" ;
  465.         }
  466.         else
  467.         {
  468.             $size = "<b>$size</b> bytes" ;
  469.         }
  470.  
  471.         #_________________________________
  472.         #
  473.         #    Add notes if applicable
  474.         #_________________________________
  475.  
  476.         if( -r "$doc/$_.notes" )
  477.         {
  478.             open(DATA, "$doc/$_.notes") ;
  479.             @notes = <DATA> ;
  480.             close(DATA) ;
  481.         }
  482.         
  483.         #_________________________________
  484.         #
  485.         # figure out which image to use
  486.         #_________________________________
  487.  
  488.         # defaults
  489.  
  490.         $image = "" ;
  491.         $url = "" ;
  492.  
  493.         # audio
  494.  
  495.         $image = "file_audio.gif" if ( /\.[aA][uU]$/ ) ;
  496.         $image = "file_audio.gif" if ( /\.[aA][iI][fF]$/ ) ;
  497.         $image = "file_audio.gif" if ( /\.aif[cf]$/ ) ;
  498.         $image = "file_audio.gif" if ( /\.[sS][nN][dD]$/ ) ;
  499.         $image = "file_audio.gif" if ( /\.[wW][aA][vV]$/ ) ;
  500.         $image = "file_audio.gif" if ( /\.[rR][aA]$/ ) ;
  501.         $image = "file_audio.gif" if ( /\.[rR][aA][mM]$/ ) ;
  502.         $image = "file_audio.gif" if ( /\.[aA][bB][sS]$/ ) ;
  503.         $image = "file_audio.gif" if ( /\.[mM][pP][2a]$/ ) ;
  504.         $image = "file_audio.gif" if ( /\.[mM][pP][2a][2a]$/ ) ;
  505.         $image = "file_audio.gif" if ( /\.[mM][pP][eE][gG][aA]$/ ) ;
  506.  
  507.         # image
  508.  
  509.         $image = "file_image.gif" if ( /\.[gG][iI][fF]$/ ) ;
  510.         $image = "file_image.gif" if ( /\.[iI][eE][fF]$/ ) ;
  511.         $image = "file_image.gif" if ( /\.tiff$/ ) ;
  512.         $image = "file_image.gif" if ( /\.[tT][iI][fF]$/ ) ;
  513.         $image = "file_image.gif" if ( /\.[jJ][pP][gG]$/ ) ;
  514.         $image = "file_image.gif" if ( /\.jpeg$/ ) ;
  515.         $image = "file_image.gif" if ( /\.[jJ][pP][eE]$/ ) ;
  516.         $image = "file_image.gif" if ( /\.rgb$/ ) ;
  517.         $image = "file_image.gif" if ( /\.ras$/ ) ;
  518.         $image = "file_image.gif" if ( /\.pcd$/ ) ;
  519.         $image = "file_image.gif" if ( /\.p[nbgp]m$/ ) ;
  520.         $image = "file_image.gif" if ( /\.x[bp]m$/ ) ;
  521.         $image = "file_image.gif" if ( /\.xwd$/ ) ;
  522.         $image = "file_image.gif" if ( /\.icon$/ ) ;
  523.         $image = "file_image.gif" if ( /\.fti$/ ) ;
  524.  
  525.         # video
  526.  
  527.         $image = "file_movie.gif" if ( /\.movie$/ ) ;
  528.         $image = "file_movie.gif" if ( /\.[mM][oO][vV]$/ ) ;
  529.         $image = "file_movie.gif" if ( /\.moov$/ ) ;
  530.         $image = "file_movie.gif" if ( /\.[mM][vV]$/ ) ;
  531.         $image = "file_movie.gif" if ( /\.[qQ][tT]$/ ) ;
  532.         $image = "file_movie.gif" if ( /\.[aA][vV][iI]$/ ) ;
  533.         $image = "file_movie.gif" if ( /\.[mM][pP][eEgGsSvV]$/ ) ;
  534.         $image = "file_movie.gif" if ( /\.[mM][pP][2sSvV][2sSvV]$/ ) ;
  535.         $image = "file_movie.gif" if ( /\.[mM][pP][eE][gG]$/ ) ;
  536.         $image = "file_movie.gif" if ( /\.[mM][pP][eE][gG][vV]$/ ) ;
  537.  
  538.         # html
  539.  
  540.         $image = "file_html.gif" if ( /\.[hH][tT][mM][lL]$/ ) ;
  541.         $image = "file_html.gif" if ( /\.[hH][tT][mM]$/ ) ;
  542.         $image = "file_html.gif" if ( /\.[sS][hH][tT][mM][lL]$/ ) ;
  543.  
  544.         # PostScript
  545.  
  546.         $image = "file_ps.gif" if ( /\.[pP][sS]$/ ) ;
  547.         $image = "file_ps.gif" if ( /\.[eE][pP][sS]$/ ) ;
  548.  
  549.         # text
  550.  
  551.         $image = "file_text.gif" if ( /\.[tT][xX][tT]$/ ) ;
  552.         $image = "file_text.gif" if ( /\.[rR][tT][xX]$/ ) ;
  553.         $image = "file_text.gif" if ( /\.[rR][tT][fF]$/ ) ;
  554.         $image = "file_text.gif" if ( /\.doc$/ ) ;
  555.         $image = "file_text.gif" if ( /\.fm$/ ) ;
  556.         $image = "file_text.gif" if ( /\.mif$/ ) ;
  557.  
  558.         # development
  559.  
  560.         $image = "file_makefile.gif" if ( /[Mm]akefile.*$/ ) ;
  561.         $image = "file_core.gif" if ( $_ eq "core" ) ;
  562.         $image = "file_h.gif" if ( /\.[hH]$/ ) ;
  563.         $image = "file_c.gif" if ( /\.c$/ ) ;
  564.         $image = "file_cxx.gif" if ( /\.[cC[xX][xX]$/ ) ;
  565.         $image = "file_cxx.gif" if ( /\.[cC]\+\+$/ ) ;
  566.         $image = "file_cxx.gif" if ( /\.C$/ ) ;
  567.         $image = "file_cxx.gif" if ( /\.[cC][cC]$/ ) ;
  568.         $image = "file_obj.gif" if ( /\.[oO]$/ ) ;
  569.         $image = "file_java.gif" if ( /\.java$/ ) ;
  570.         $image = "file_javaclass.gif" if ( /\.class$/ ) ;
  571.  
  572.         # showcase
  573.  
  574.         $image = "file_showcase.gif" if ( /\.sc$/ ) ;
  575.         $image = "file_showcase.gif" if ( /\.slides$/ ) ;
  576.         $image = "file_showcase.gif" if ( /\.sho$/ ) ;
  577.         $image = "file_showcase.gif" if ( /\.show$/ ) ;
  578.  
  579.         # command scripts
  580.  
  581.         $image = "file_shell.gif" if ( /\.pl$/ ) ;
  582.         $image = "file_shell.gif" if ( /\.sh$/ ) ;
  583.         $image = "file_shell.gif" if ( /\.csh$/ ) ;
  584.  
  585.         # DOS/Windows
  586.  
  587.         $image = "file_ms_exe.gif" if ( /\.[bB][aA][tT]$/ ) ;
  588.         $image = "file_ms_exe.gif" if ( /\.[eE][xX][eE]$/ ) ;
  589.         $image = "file_ms_exe.gif" if ( /\.[cC][oO][mM]$/ ) ;
  590.         $image = "file_ms_pp.gif" if ( /\.[pP][pP][tT]$/ ) ;
  591.         $image = "file_ms_access.gif" if ( /\.[aA][dD][bB]$/ ) ;
  592.         if ( /\.[xX][lL].$/ )
  593.         {
  594.             open(FILE, "$ROOT/$PATH/$_") ;
  595.             read(FILE,$buf,3);
  596.             $image = "file_ms_excel.gif"
  597.             if (substr($buf,0,2) eq "\xd0\xcf" ||
  598.                 substr($buf,0,1) eq "\x09" &&
  599.                 substr($buf,2,1) eq "\x06") ;
  600.             close(FILE);
  601.         }
  602.         if ( /\.[dD][oO][cCtT]$/ )
  603.         {
  604.             open(FILE, "$ROOT/$PATH/$_") ;
  605.             read(FILE,$buf,2);
  606.             $image = "file_ms_word.gif"
  607.             if ($buf eq "\xfe\x37" ||
  608.                 $buf eq "\xdb\xa5" ||
  609.                 $buf eq "\xd0\xcf") ;
  610.             close(FILE);
  611.         }
  612.         if ( /\.[fF][mM]$/ )
  613.         {
  614.             open(FILE, "$ROOT/$PATH/$_") ;
  615.             read(FILE,$buf,4);
  616.             $image = "file_claris_fm.gif"
  617.             if ($buf eq "\x00\x01\x00\x00" ||
  618.                 $buf eq "\x00\x02\x00\x00") ;
  619.             close(FILE);
  620.         }
  621.  
  622.  
  623.         # other
  624.  
  625.         $image = "file_iv.gif" if ( /\.iv$/ ) ;
  626.         $image = "file_iv.gif" if ( /\.ano$/ ) ;
  627.         $image = "file_tar.gif" if ( /\.[tT][aA][rR]$/ ) ;
  628.         $image = "file_compress.gif" if ( /\.[gG][zZ]$/ ) ;
  629.         $image = "file_compress.gif" if ( /\.[tT][gG][zZ]$/ ) ;
  630.         $image = "file_compress.gif" if ( /\.Z$/ ) ;
  631.         $image = "file_vrml.gif" if ( /\.vrml$/ ) ;
  632.         $image = "file_vrml.gif" if ( /\.vrml\.gz$/ ) ;
  633.         $image = "file_vrml.gif" if ( /\.wrl$/ ) ;
  634.         $image = "file_vrml.gif" if ( /\.wrl\.gz$/ ) ;
  635.         $image = "file_midi.gif" if ( /\.[mM][iI][dD]$/ ) ;
  636.         $image = "file_midi.gif" if ( /\.[mM][iI[dD][iI]$/ ) ;
  637.         $image = "file_pdf.gif" if ( /\.[pP][dD][fF]$/ ) ;
  638.         $image = "file_director.gif" if ( /\.[dD][cCxXiI][rR]$/ ) ;
  639.  
  640.         # generic ms-windows application data
  641.                 # (i.e. has suffix, no types above match)
  642.         if ( $image eq "" && /..*\...*$/ )
  643.         {
  644.             open(FILE, "$ROOT/$PATH/$_") ;
  645.             read(FILE,$buf,16);
  646.             $image = "file_ms_generic.gif"
  647.             if ($buf eq "\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1\x00\x00\x00\x00\x00\x00\x00\x00" ||
  648.                 $buf eq "\x09\x04\x06\x00\x00\x00\x10\x00\xf6\x05\x5c\x00\x20\x00\x03\x2e") ;
  649.             close(FILE);
  650.         }
  651.  
  652.         # types without suffix
  653.         
  654.         if ( $image eq "" )
  655.         {
  656.             open(FILE, "$ROOT/$PATH/$_") ;
  657.             if ( $string = <FILE> )
  658.             {
  659.             # WebJumper
  660.             if ( $string =~ /^\#SGIWebJumpsite/ ||
  661.                  $string =~ /^\#NetscapeURL/ )
  662.             {
  663.                 $image = "file_webjumper.gif";
  664.                 while ( $string = <FILE> )
  665.                 {
  666.                 $string =~ s/\n$// ;
  667.  
  668.                 # look for ://, and other url types
  669.                 if ( $string =~ /:\/\// ||
  670.                     $string =~ /^mailto:/ ||
  671.                     $string =~ /^file:/ ||
  672.                     $string =~ /^about:/ ||
  673.                     $string =~ /^news:/ ||
  674.                     $string =~ /^mailbox:/ )
  675.                 {
  676.                     # don't view it, go to it.
  677.                     $url = $string ;
  678.                     last ;
  679.                 }
  680.                 else
  681.                 {
  682.                     # use as a note, if no .notes file
  683.                     @notes = ( $string )
  684.                     if ( @notes == 0 &&
  685.                          $string ne "URL Pasted into Desktop" ) ;
  686.                 }
  687.                 }
  688.             }
  689.  
  690.             # command script
  691.             $image = "file_shell.gif" if ( $string =~ /^\#!\/bin\/.*sh/ ) ;
  692.             $image = "file_shell.gif" if ( $string =~ /^\#!\/usr\/s*bin\/perl/ ) ;
  693.             }
  694.             close(FILE) ;
  695.         }
  696.  
  697.         # generic executable
  698.         
  699.         if ( $image eq "" )
  700.         {
  701.             $image = "file_exec.gif" if ( -x "$ROOT/$PATH/$_" ) ;
  702.         }
  703.  
  704.         # default to generic data file icon
  705.  
  706.         $image = "file_data.gif" if ( $image eq "" ) ;
  707.  
  708.         # default to view data
  709.  
  710.         $url = "$USERPATH/$_" if ( $url eq "" ) ;
  711.  
  712.         #_________________________________
  713.         #
  714.         #    Diplay the data in table form
  715.         #_________________________________
  716.  
  717.         print <<ENDOFTEXT ;
  718. <tr>
  719.     <td>
  720.         <a href="$url"><img src="/outbox/images/$image" align=middle border=0></a>
  721.     </td>
  722.     <td>
  723.         <a href="$url">$_</a>
  724.     </td>
  725.     <td>
  726.         $size
  727.     </td>
  728.     <td align=left>
  729. ENDOFTEXT
  730.                 if ( $HANDLER_DISABLED == 0 ) {
  731.                     print "<a href=\"/cgi-bin/handler$PATH/$_?data=Download\">$dltext</a>\n" ;
  732.         }
  733.                 print "        </td>\n" ;
  734.  
  735.         #_________________________________
  736.         #
  737.         #    If there is a .notes file,
  738.         #    show the message within the
  739.         #    HTML doc.
  740.         #_________________________________
  741.  
  742.         if ( @notes > 0 )
  743.         {
  744.             print "<td>" ;
  745.             foreach (@notes)
  746.             {
  747.                 print ;
  748.             }
  749.             print "</td>\n" ;
  750.             @notes = () ;
  751.         }
  752.         print "</tr>\n" ;
  753.     }
  754.     print "</table></center>\n" if $first == 0 ;
  755. }
  756.  
  757. #__________________________________________________________
  758.  
  759. sub ListShort
  760. {
  761.     local($size) = $#_ + 1 ;
  762.     local($i) ;
  763.     local($j) ;
  764.     local($index) ;
  765.     local($cols) = 3 ;
  766.     local($rows) = $size / $cols ;
  767.     local($left) = $size % $cols ;
  768.  
  769.     return if $size == 0 ;
  770.  
  771.     $rows = sprintf("%.0d", $rows) ;
  772.     $rows++ if $left > 0 ;
  773.     
  774.     print <<ENDOFTEXT ;
  775.  
  776. </center>
  777. <h3>Shared Files:</h3>
  778.  
  779. <table cellpadding=5 cellspacing=3 border width="100%"><tr><td>
  780. <table cellpadding=3 width="100%">
  781. ENDOFTEXT
  782.     LOOP:
  783.     for( $i = 0 ; $i < $rows ; $i++ )
  784.     {
  785.         print "<tr>\n" ;
  786.         for( $j = 0 ; $j < $cols ; $j++ )
  787.         {
  788.             $index = $i + $j * $rows ;
  789.             if( $index >= $size )
  790.             {
  791.                 print "<td></td>\n" ;
  792.                 next ;
  793.             }
  794.             print <<ENDOFTEXT ;
  795. <td>
  796.     <a href="$PATH/$_[$index]">
  797.         <img src="/outbox/images/file_data.gif" align=middle border=0>  
  798.         $_[$index]
  799.     </a>
  800. </td>
  801. ENDOFTEXT
  802.         }
  803.         print "</tr>\n" ;
  804.     }
  805.  
  806.     print <<ENDOFTEXT ;
  807. </table>
  808. </td></tr></table>
  809. ENDOFTEXT
  810. }
  811.  
  812. #__________________________________________________________
  813.  
  814. sub ListLong
  815. {
  816.     local($unit) ;
  817.     local(@other) ;
  818.     local($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) ;
  819.     local($atime, $mtime, $ctime) ;
  820.     local($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) ;
  821.     
  822.     return if $#_ == -1 ;
  823.     
  824.     print <<ENDOFTEXT ;
  825.  
  826. <h3>Shared Files:</h3>
  827. <table cellpadding=5 cellspacing=3 border width="100%">
  828. <tr><td>
  829. <pre>
  830.  
  831. ENDOFTEXT
  832.  
  833.     foreach (@_)
  834.     {
  835.         #_________________________________
  836.         #
  837.         #    stat document and get the 
  838.         #    pertinent info on it.  Also
  839.         #    get a unit for the size, ie
  840.         #    bytes or Kb, etc
  841.         #_________________________________
  842.         
  843.         ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  844.             $atime, $mtime, $ctime, @other) =
  845.             stat("$doc/$_") ; 
  846.  
  847.         if( $size == 1 )
  848.         {
  849.             $unit = "byte" ;
  850.         }
  851.         elsif( $size >= 1024 )
  852.         {
  853.             $size = $size / 1024 ;
  854.             $size = sprintf("%.0d", $size) ;
  855.             $unit = "KB" ;
  856.         }
  857.         else
  858.         {
  859.             $unit = "bytes" ;
  860.         }
  861.  
  862.         #_________________________________
  863.         #
  864.         #    Get last mod time
  865.         #_________________________________
  866.  
  867.         ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,@other) = 
  868.             localtime($ctime) ;
  869.         $theDay   = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[$wday] ;
  870.         $theMonth = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$mon] ;
  871.         $date     = sprintf("$theDay $theMonth $mday %02d:%02d:%02d 19$year",
  872.                             $hour, $min, $sec) ;
  873.  
  874.         #_________________________________
  875.  
  876.         local($filler) = " " x (25 - length($_)) ;
  877.         $filler = 0 if $filler < 0 ;
  878.         print sprintf("<a href=\"$PATH/$_\"><img src=\"/outbox/images/file_data.gif\" align=middle border=0>  %.25s</a>%s %6d %-5.5s %s\n", $_, $filler, $size, $unit, $date) ;
  879.     }
  880.  
  881.     print <<ENDOFTEXT ;
  882. </pre>
  883. </td></tr>
  884. </table>
  885. ENDOFTEXT
  886. }
  887.  
  888.